#include<bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
#define LL long long 
#define ULL unsigned long long 
#define PII pair<int, int>
#define lowbit(x) (x & -x)
#define Mid ((l + r) >> 1)
#define ALL(x) x.begin(), x.end()
#define endl '\n'
#define fi first 
#define se second

const int INF = 0x7fffffff;
const int Mod = 1e9 + 7;
const int N = 10000 + 10; 

struct Edge {int to, weight;};  // 边
vector<vector<Edge>> tree;      //用于存储树的结构
int n, dp[3][N], id[N];

void dfs1(int x, int y) {
    for(auto i : tree[x]) {//正向最大距离
        if(i.to == y) continue;
        dfs1(i.to, x);
        if(dp[0][x] < dp[0][i.to] + i.weight) {
            dp[0][x] = dp[0][i.to] + i.weight;
            id[x] = i.to;
        }
    }
    for(auto i : tree[x]) {//正向次大距离
        if(i.to == y) continue;
        if(id[x] == i.to) continue;
        dp[1][x] = max(dp[1][x], dp[0][i.to] + i.weight);
    }
}

void dfs2(int x, int y) {
    for(auto i : tree[x]) {//反向最大距离
        if(i.to == y) continue;
        if(i.to == id[x])
            dp[2][i.to] = max(dp[2][x], dp[1][x]) + i.weight;
        else
            dp[2][i.to] = max(dp[2][x], dp[0][x]) + i.weight;
        dfs2(i.to, x);
    }
}

void init() {
    tree.clear(); tree.resize(n + 1);
    memset(dp, 0, sizeof dp);
    memset(id, 0, sizeof id);
}

void Solved() { 
    while(cin >> n) {
        init();
        for(int i = 2; i <= n; i ++ ) {
            int x, y; cin >> x >> y;
            tree[x].push_back({i, y});
            tree[i].push_back({x, y});
        }
        dfs1(1, -1); dfs2(1, -1);

        for(int i = 1; i <= n; i ++ ) {
            cout << max(dp[0][i], dp[2][i]) << endl;
        }
    }
}

signed main(void) {
    IOS

    int ALL = 1; 
    // cin >> ALL;
    while(ALL -- ) Solved();
    // cout << fixed;//强制以小数形式显示
    // cout << setprecision(n); //保留n位小数

    return 0;
}